import { getOtherUserHomeInfo, setFollow, checkQuiz } from "@/static/js/my.js";

var isGo = true;

export default {
  data() {
    return {
      id: "",
      info: {}, //主要信息

      //认证专业人士
      majorTypes: "",

      //回答
      answer: {
        count: 0,
        list: [],
      },
      //话题
      usertopic: {
        count: 0,
        list: [],
      },
      is_focus: 0,
    };
  },
  onLoad(e) {
    this.id = e.id;
    let userInfo = uni.getStorageSync("userInfo");
    if (this.id == userInfo.id) {
      uni.redirectTo({
        url: '/pages/my/homeCenter/home'
      })
      return;
    }
    this.getOtherUserHomeInfo();
  },
  methods: {
    async getOtherUserHomeInfo() {
      var params = {
        uid: this.id,
      };
      let res = await getOtherUserHomeInfo(params);
      if (res.code == 1) {
        this.usertopic = res.data.usertopic;
        this.answer = res.data.answer;
        this.info = res.data.info;
        this.is_focus = res.data.is_focus;
        this.majorTypes = res.data.major_types;
      } else {
        this.$tools.msg(res.msg);
      }
    },
    //关注
    async gzFun() {
      let params = {
        uid: this.id,
      };
      let res = await setFollow(params);
      if (res.code == 1) {
        this.$tools.msg(this.is_focus == 1 ? "取消成功" : "关注成功");
        this.is_focus = 1 - this.is_focus;
      } else {
        this.$tools.msg(res.msg);
      }
    },
    toHome(item) {
      uni.navigateTo({
        url: "/pages/my/homeCenter/taHome?id=" + item.uid,
      });
    },
    toInfo(item) {
      uni.navigateTo({
        url: "/quiz/askInfo/index?id=" + item.id,
      });
    },

    async goCheck(item) {
      if (!isGo) return;
      isGo = false;
      const res = await checkQuiz({
        quiz_id: item.quiz_id,
      });
      isGo = true;
      if (res.code == 1) {
        uni.navigateTo({
          url: item.url,
        });
      } else if (res.code == 3) {
        uni.showToast({
          title: res.msg,
          icon: "none",
        });
      }
    },
    goBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};